package com.ddz.library.screen

import android.content.Context
import android.graphics.Rect
import android.view.WindowManager
import com.ddz.library.JKLibrary

object JKScreenUtils {
    /**
     * 状态栏高度
     */
    fun getStatusBarHeight(context:Context): Int {
        val resources = context.resources
        val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
        return resources.getDimensionPixelSize(resourceId)
    }

    /**
     * 获取窗口矩形大小信息
     */
    fun getWindowRect(windowManager: WindowManager?): Rect {
        val rect: Rect
        if (windowManager != null && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
            rect = windowManager.currentWindowMetrics.bounds
        } else {
            rect = Rect(0, 0, 0, 0)
            rect.right = JKLibrary.context!!.resources.displayMetrics.widthPixels
            rect.bottom = JKLibrary.context!!.resources.displayMetrics.heightPixels
        }
        return rect
    }
}